/*
*  Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
*/
package com.pitop.material.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.material.entity.MaterialSupplier;
import com.pitop.material.service.MaterialSupplierSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物料供应商 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/materialSupplier")
@Slf4j
@Api(value = "物料供应商控制器", description = "物料供应商控制器")
public class MaterialSupplierCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MaterialSupplierSV materialSupplierSV;

    /**
     * 查询MaterialSupplier一个详情信息
     *
     * @param id
     * @param suppierCode  供应商编码
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MaterialSupplier一个详情信息", notes = "查询MaterialSupplier一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public MaterialSupplier load(Long id, String suppierCode, String materialCode) {
        if (id == null) {
            return null;
        }
        if (suppierCode == null) {
            return null;
        }
        if (materialCode == null) {
            return null;
        }
        MaterialSupplier materialSupplier = materialSupplierSV.load(id, suppierCode, materialCode);
        log.info(JSON.toJSONString(materialSupplier));
        return materialSupplier;
    }


    /**
     * 根据条件id查询MaterialSupplier一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询MaterialSupplier一个详情信息", notes = "查询MaterialSupplier一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public MaterialSupplier loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        MaterialSupplier materialSupplier = materialSupplierSV.loadById(id);
        log.info(JSON.toJSONString(materialSupplier));
        return materialSupplier;
    }

    /**
     * 根据条件suppierCode查询MaterialSupplier一个详情信息
     *
     * @param suppierCode 供应商编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MaterialSupplier一个详情信息", notes = "查询MaterialSupplier一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/suppierCode/{suppierCode}")
    @ResponseBody
    public MaterialSupplier loadBySuppierCode(@PathVariable String suppierCode) {
        if (suppierCode == null) {
            return null;
        }
        MaterialSupplier materialSupplier = materialSupplierSV.loadBySuppierCode(suppierCode);
        log.info(JSON.toJSONString(materialSupplier));
        return materialSupplier;
    }

    /**
     * 根据条件materialCode查询MaterialSupplier一个详情信息
     *
     * @param materialCode 物料编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MaterialSupplier一个详情信息", notes = "查询MaterialSupplier一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "materialCode", value = "物料编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/materialCode/{materialCode}")
    @ResponseBody
    public MaterialSupplier loadByMaterialCode(@PathVariable String materialCode) {
        if (materialCode == null) {
            return null;
        }
        MaterialSupplier materialSupplier = materialSupplierSV.loadByMaterialCode(materialCode);
        log.info(JSON.toJSONString(materialSupplier));
        return materialSupplier;
    }


    /**
     * 查询MaterialSupplier信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MaterialSupplier信息集合", notes = "查询MaterialSupplier信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<MaterialSupplier> list(@RequestBody @ApiIgnore MaterialSupplier materialSupplier, Integer curPage, Integer pageSize) {
        Page<MaterialSupplier> page = new Page<MaterialSupplier>(pageSize, curPage);
        List<MaterialSupplier> materialSuppliers = materialSupplierSV.list(materialSupplier, page.genRowStart(), page.getPageSize());
        int total = materialSupplierSV.count(materialSupplier);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return materialSuppliers;
    }


    /**
     * 查询MaterialSupplier信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MaterialSupplier信息集合", notes = "查询MaterialSupplier信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<MaterialSupplier> listByPk(Long id, String suppierCode, String materialCode, Integer curPage, Integer pageSize) {
        Page<MaterialSupplier> page = new Page<MaterialSupplier>(pageSize, curPage);
        List<MaterialSupplier> materialSuppliers = materialSupplierSV.list(id, suppierCode, materialCode, page.genRowStart(), page.getPageSize());
        int total = materialSupplierSV.count(id, suppierCode, materialCode);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return materialSuppliers;
    }

    /**
     * 统计MaterialSupplier信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计MaterialSupplier信息数量根据主键", notes = " 统计MaterialSupplier信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String suppierCode, String materialCode) {
        return materialSupplierSV.count(id, suppierCode, materialCode);
    }

    /**
     * 统计MaterialSupplier信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计MaterialSupplier信息数量", notes = "统计MaterialSupplier信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "level", value = "供应商级别 1,2,3 数字代表级别", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody MaterialSupplier materialSupplier) {
        return materialSupplierSV.count(materialSupplier);
    }


    /**
     * 创建MaterialSupplier
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建MaterialSupplier", notes = "创建MaterialSupplier")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "level", value = "供应商级别 1,2,3 数字代表级别", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public MaterialSupplier build(@RequestBody @ApiIgnore MaterialSupplier materialSupplier) {
        materialSupplierSV.save(materialSupplier);
        return materialSupplier;
    }


    /**
     * 修改MaterialSupplier
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改MaterialSupplier", notes = "修改MaterialSupplier")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query"),
            @ApiImplicitParam(name = "level", value = "供应商级别 1,2,3 数字代表级别", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：启用 enable,禁用 disable", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public MaterialSupplier modify(@RequestBody @ApiIgnore MaterialSupplier materialSupplier) {
        materialSupplierSV.modify(materialSupplier);
        return materialSupplier;
    }


    /**
     * 删除MaterialSupplier
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除MaterialSupplier", notes = "删除MaterialSupplier")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "suppierCode", value = "供应商编码", paramType = "query"),
            @ApiImplicitParam(name = "materialCode", value = "物料编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String suppierCode, java.lang.String materialCode) {
        materialSupplierSV.delete(id, suppierCode, materialCode);
        return BeanRet.create(true, "删除MaterialSupplier成功");
    }

}
